﻿layui.config({
    base: "Scripts/"
}).use(['form', 'layer', 'jquery', 'laypage'], function () {
    var form = layui.form,
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
		$ = layui.jquery;


    function AddSP(data) {

      
        var ids1 = $('#Position option:selected').val();
        var ids2 = $('#Department option:selected').val();//下拉框选中的值  id  传到控制器
        var pname1 = $('#jobnumbers').val();
        var pname2 = $('#moneys').val();//文本框的值 传到控制器
        $.ajax({
            type: "post",
            url: "/Shows/Entry",//方法
            data:
                {
                    "PositionId": ids1,
                    "DepartmentId": ids2,//对应实体数据库字段  新建实体类
                    "JobNumber": pname1,
                    "TrialPay": pname2 //对应实体数据库字段

                },
            dataType: "json",
            success: function (result) {
                if (result.State == 1)
                    layer.alert(result.Message, { icon: 1, time: 1.5 * 1000 });
                else
                    layer.msg(result.Message, { icon: 7, time: 1.5 * 1000 });
            }
        });
    };



    function Select() {
    
        var url = "/Shows/Position";
        $.post(url, function (result) {
            var departments = JSON.parse(result.data);
            var deptSelect = $("#Position");
           
            layui.each(departments, function (index, data) {
                var deptOption = $("<option value='" + data.Id+ "'>" + data.P_Name + "</option>");
                deptSelect.append(deptOption);
            });
            form.render();
        });
    };

    function Select2() {
       
        var url = "/Shows/Department";
        $.post(url, function (result) {
            var departments = JSON.parse(result.data);
            var deptSelect = $("#Department");
         
            layui.each(departments, function (index, data) {
                var deptOption = $("<option value='" + data.D_Id + "'>" + data.D_Name + "</option>");
                deptSelect.append(deptOption);
            });
            form.render();
        });
    };
    $(function () {
       
        Select();
        Select2();
        //监听提交  subForm为lay-filter属性
        form.on('submit(ApproveForm)', function (data) {
          
            AddSP(data);

            return false;
        });

     
     
    });
});